/*
 * Getrap
 * Copyright 2008(C) Grzegorz 'milyges' Glinski
 *
 *
 *  This program is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU General Public License as published by the Free
 *  Software Foundation; either version 2 of the License, or (at your option)
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 *  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
 *  for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
*/
#include <fAddFiles.h>
#include <QFileDialog>
#include <QByteArray>

FAddFiles::FAddFiles(QWidget * parent, Qt::WFlags f) : QDialog(parent, f)
{
 ui.setupUi(this);
 connect(ui.bntFromFile, SIGNAL(clicked()), this, SLOT(loadFromFile()));
}

FAddFiles::~FAddFiles()
{
}

QStringList FAddFiles::getLinks(void)
{
 return ui.textLinks->toPlainText().split('\n');
}

void FAddFiles::loadFromFile(void)
{
 QFile * file;
 QFileDialog wnd(this);
 QByteArray line;
 wnd.setAcceptMode(QFileDialog::AcceptOpen);
 wnd.setFileMode(QFileDialog::ExistingFile);
 wnd.exec();
 if (wnd.result() == QDialog::Accepted)
 {
  file = new QFile(wnd.selectedFiles().at(0).toLocal8Bit().constData());
  if (!file->open(QIODevice::ReadOnly | QIODevice::Text))
  {
   delete file;
   return;
  }
  while (!file->atEnd())
  {
   line = file->readLine();
   ui.textLinks->append(QString(line).replace("\n", ""));
  }
  delete file;
 }
}
